<!-- 科内-确认取货 -->
<template>
	<ListLayout>
		<AttachmentCard ref="AttachmentCard"></AttachmentCard>
		<SignCard ref="SignCard"></SignCard>
		<!-- 科内取 有待评价 -->
		<!-- // 科内第一次取走需要评价【排除厂家】 -->

		<!-- <template v-if="routerParams.processState =='wait_dept_takeaway'">
			<EvaluationCard ref="EvaluationCard"></EvaluationCard>
		</template> -->
		<template #footer>
			<HButtonGroup @leftClick="onCancel" @rightClick="onConfirmPickup">
				<template #left>
					取消
				</template>
				<template #right>
					确认取走
				</template>
			</HButtonGroup>
		</template>
	</ListLayout>

</template>

<script>
	import ListLayout from '@/components/layout/listLayout.vue'
	import QuoteCard from '@/components/card/sendRepair/factory/quote.vue'
	import AttachmentCard from '@/components/card/attachment.vue'
	import HButtonGroup from '@/components/buttonGroup/groupTwo.vue'
	import EvaluationCard from '@/components/card/evaluation.vue'
	import SignCard from '@/components/card/sign.vue'
	import ReapirApi from '@/apis/repair.js'
	import { mathSum } from '@/filter/index.js'
	import { attachmentFormatter } from '@/common/submitFormatter.js'
	import SendRepairRouterConfig from '@/sendRepair/routerConfig.js'
	export default {
		components: {
			ListLayout,
			QuoteCard,
			AttachmentCard,
			EvaluationCard,
			SignCard,
			HButtonGroup,

		},
		data() {
			return {
				routerParams: {
					id: '',
					processState: ''
				}
			}
		},
		computed: {

		},
		async onLoad(query) {

			const {
				id,
				process_state
			} = query
			this.$set(this.routerParams, 'id', id)
			this.$set(this.routerParams, 'processState', process_state || '')
			let res = await ReapirApi.common.getDetail(id)
			if (res.code === 0) {
				let data = res.body || {}
				this.$set(this.routerParams, 'processState', data.repairInfo.currState || '')
			}

		},

		methods: {
			onCancel() {
				wx.navigateBack()
			},
			toast() {
				wx.showToast({
					title: '取走成功!',
					icon: 'success',
					duration: 1000,
					complete() {
						wx.redirectTo({
							url: SendRepairRouterConfig.Department.Index
						})
					}
				})
			},
			async onConfirmPickup() {
				let {
					AttachmentCard,
					SignCard,
					// EvaluationCard
				} = this.$refs
				let attachment = AttachmentCard.$data.attachment
				// let {
				// 	manner,
				// 	quality,
				// 	responseTimeliness,
				// 	text
				// } = EvaluationCard?.$data.evaluationData || {}


				SignCard.upSign(async (file) => {
					let params = {
						// 送修id不能为空
						repairId: this.routerParams.id,
						// 签名
						autograph: '',
						// 签名地址
						sign: file?.url || '',
						// 意见与建议
						commentSuggestion: '',
						// 评价录音附件
						evaluateEnclosure: '',
						// 附件
						enclosure: attachmentFormatter(attachment),
						// 服务态度
						serviceAttitude: '',
						// 服务质量
						serviceQuality: '',
						// 响应时效
						responsePrescription: '',
						// 评价结果
						evaluateResult: '',
					}
					await ReapirApi.department.comfirmPickUp(params)
					this.toast()
				})
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
